package com.itheima.prize.commons.utils;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
 * 密码工具类
 */
public class PasswordUtil {
	

	public String md5(String inputStr) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] digest = md.digest(inputStr.getBytes());
			StringBuilder sb = new StringBuilder();
			for (byte b : digest) {
				sb.append(String.format("%02x", b & 0xff)); // 确保两位，补零
			}
			return sb.toString();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 密码加密
	 */
	public static String encodePassword(String password) {
		return new PasswordUtil().md5(password);
	}
	
	public static void main(String[] args) {
		System.out.println(encodePassword("123456"));
	}

}
